mini.parse();

var baseUrl = "http://localhost:8080/DSMP";
var grid=mini.get("grid1");
//分页控件
var pager = grid.getBottomPager();


//刷新按钮
function Refresh() {
    form.reset();
    // request('0',pager.getPageSize());
}
//返回
function cback() {
    mini.alert("返回")
}

//查询
function Search() {
    var aaa=form.getData();
    console.log(aaa);
    aaa=JSON.stringify(aaa);
    console.log(aaa);
    $.ajax({
        url: baseUrl+"/moduleDeclaration/find.do",
        type: "post",
        contentType: "application/json",
        data:aaa,
        success: function(data) {//请求成功完成后要执行的方法
            console.log(data);
            grid.setData('');
            grid.setData(data.obj);
            mini.after(data.msg)
        },
        error:function(data){
            mini.alert(cuole);
        }
    });
}

/*var griddata=[
    {"column1":"rs","column2":"1","column3":"王多多","column4":1,"column5":28,"column6":"usa"},
    {"column1":"cw","column2":"2","column3":"王健林","column4":1,"column5":19,"column6":"cn"},
    {"column1":"cw","column2":"3","column3":"王思聪","column4":1,"column5":21,"column6":"jp"},
    {"column1":"rs","column2":"4","column3":"胡歌","column4":1,"column5":21,"column6":"en"},
    {"column1":"rs","column2":"5","column3":"张卫健","column4":2,"column5":21,"column6":"de"},
    {"column1":"rs","column2":"6","column3":"血杀保健","column4":1,"column5":21,"column6":"fr"}
]
grid.setData(griddata);*/


//页面初始化
(function(){
    request('0',pager.getPageSize());
})();
//请求grid接口
function request(pageIndex,pageSize){
    var pageIndex = pager.getPageIndex()
    var pageSize = pager.getPageSize();

    var pageObj = {
        current: pageIndex,
        size: pageSize,
    }

    var pageStr = JSON.stringify(pageObj);
     $.ajax({
         url: baseUrl+"/moduleDeclaration/findAllDeclaration.do",
         type: "post",
         contentType: "application/json",
         data:pageStr,
         success: function(data) {//请求成功完成后要执行的方法
             console.log(data);
             // data=JSON.parse(data)    //如果字符串的话，转换成json
             grid.setData(data.obj);
             pager.set({"totalCount": data.attributes.total})
         },
         error:function(data){
             mini.alert(cuole);
         }
     });
}

//分页
grid.on("beforeload", function (e) {
    //阻止本来的翻页功能
    e.cancel = true;
    //当前页码
    var cunrrentPageIndex = grid.getPageIndex();
    //点击按钮之后的页码
    var pageIndex = e.data.pageIndex;
    //设置当前页数值
    pager.set({"pageIndex": pageIndex});
    //数据总数
    //var pageCount = pubPageCount;
    pager.set({"pageIndex": pageIndex});
    request(pageIndex + 1, pager.getPageSize());
});
//新增页面
function add() {
    mini.open({
        targetWindow: window,
        url:"mdmanagementinfo.html",
        title:"新增模块",
        height:"90%",
        width:"80%",
        showMaxButton: true,

        setReadOnly:false,
        onload: function () {
            var iframe = this.getIFrameEl();//备份这个跨子页面窗口
            var data = {  action: "new"};//父传值给子页面
        },
        ondestroy: function (action) {
            if(action=="ok"){
                // request('0',pager.getPageSize());
                grid.reload();    //页面重新加载

            }
        }
    })
}
//编辑页面
function edit() {
    var row=grid.getSelected();

    if(row!=undefined){
        mini.open({

            targetWindow: window,
            url:"mdmanagementinfo.html",
            title:"编辑模块",
            height:"90%",
            width:"80%",
            showMaxButton: true,
            showModal:Boolean,
            allowResize:Boolean,
            setReadOnly:false,
            onload: function () {
                var iframe = this.getIFrameEl();//备份这个跨子页面窗口
                var data = {  action: "edit",row:row };//父传值给子页面
                iframe.contentWindow.SetData(data);//跨字串后页面渲染data
            },
            ondestroy: function (action) {
                if(action=="edit"){
                    // request('0',pager.getPageSize());
                    grid.reload();    //页面重新加载

                }
            }
        })
    }else{
        mini.alert("请选择一条数据")
    }
}

//删除
function removeRow(){
    var rows=grid.getSelecteds();
    console.log(rows);
    var ids= '';
    rows.forEach(function(item){
        ids+=item.moduleDeclarationId+","
    })
    console.log(ids,'ids');
    var param = {params:ids}
    var params=JSON.stringify(param);
    if (rows.length>0) {      //当一条都不选时提示让选一条
        console.log(ids);
        $.ajax({
            url:baseUrl+"/moduleDeclaration/delModule.do",
            data:params,
            contentType: "application/json",
            type:"post",
            success:function (data) {
                mini.alert(data.msg)
                request();
            }
        })
    }else{
        mini.alert("请至少选中一行记录")
    }
}